package rmi;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;

/**
 * Created by Dell on 2016/10/25.
 */
public class RMIConfig {
    private static Document document=null;

    static{

        try {
            DocumentBuilder db  = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            RMIConfig.document = db.parse("server/config/rmiServerConfig.xml");
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static int getServerPort(){
        NodeList nl = RMIConfig.document.getElementsByTagName("port");
        return Integer.parseInt(nl.item(0).getTextContent());
    }
}
